class Solution(object):
    def findMinMoves(self, machines):
        """
        :type machines: List[int]
        :rtype: int
        """
        n = len(machines)
        if n == 0:
            return 0
        if not (sum(machines) % n) == 0:
            return -1

        ave_clo = sum(machines) / n

        step, num , part = 0, 0, 0
        for i in range(n):
            num = machines[i] - ave_clo      
            part += num
            step = max(step, num, abs(part))


        return step
        

if __name__ == "__main__":
    so = Solution()
    a = [0]
    print(so.findMinMoves(a))